import { createApp } from 'vue'
import App from './App.vue'

let instance = null

function render(props) {
    if (!props) {
        return
    }
    const { container } = props
    const mountNode = container ? container.querySelector("#app") : "#app"
    instance = createApp(App)
    instance.mount(mountNode)
}

// 非qiankun模式下，直接渲染
if (!window.__POWERED_BY_QIANKUN__) {
    mount({})
}

export async function bootstrap() {
    console.log('vue3 app bootstraped')
}

export async function mount(props) {
    console.log('vue3 app mount', props)
    render(props)
}

export async function unmount() {
    if (!instance) {
        return
    }
    instance.unmount()
    // 清空容器
    const container = instance._container
    if (container) {
        container.innerHTML = ''
    }
    instance = null
}